<?php
class AssignWidget extends CWidget
{
    public $userId=0;
    public $exceptRoles = array();
    public $allowAjaxAssign = TRUE;
    
    public function run()
    {
        $roles = FSM::run('Admin.permission.getRoles')->roles;
        $assigned = FSM::run('Admin.permission.getAssigned', array('userId'=>$this->userId, 'roles'=>$roles))->assigned;
        if (count($roles))
        {
            $roles = array_keys($roles);
            $roles = array_combine($roles, $roles);
            if (is_array($this->exceptRoles) && count($this->exceptRoles) > 0)
            {
                foreach($this->exceptRoles as $exceptRole)
                {
                    if (isset($roles[$exceptRole])) unset($roles[$exceptRole]);
                }
            }
        }
        
        $this->render('assign', array('roles'=>$roles, 'assigned'=>$assigned));
    }
}